package demo.observer;


import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author : feixiang.li
 * @since : 2025-09-17 16:42
 */
public class WeatherStation {

    TvStation tvStation;

    public WeatherStation(TvStation tvStation) {
        this.tvStation = tvStation;
    }

    public String getInfo() {
        if (new Random().nextBoolean()) {
            return "晴天";
        }
        return "阴天";
    }

    public void start() {
        while (true) {
            String info = getInfo();
            WeatherUpdateEvent event = new WeatherUpdateEvent(info);
            tvStation.pushEvent(event);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
